package org.hako.recite.word.words.impl;

import java.util.BitSet;
import java.util.Random;

/**
 * Random index handler of part words.
 * 
 * @author xnnyygn
 */
public class PartRandomIndexHandler extends AbstractRandomIndexHandler {

    /**
     * Create
     * 
     * @param wordCount 
     */
    public PartRandomIndexHandler(int wordCount) {
        this(wordCount, wordCount);
    }

    /**
     * Create
     * 
     * @param wordCount
     * @param testWordLimit 
     */
    public PartRandomIndexHandler(int wordCount, int testWordLimit) {
        this(wordCount, 0, testWordLimit);
    }

    /**
     * Create
     * 
     * @param wordCount
     * @param testWordOffset
     * @param testWordLimit 
     */
    public PartRandomIndexHandler(int wordCount, int testWordOffset, 
            int testWordLimit) {
        super(testWordLimit);
        BitSet bitSet = new BitSet(wordCount);
        Random random = new Random();
        for (int i = 0; i < testWordLimit; i++) {
            int value = -1;
            do {
                value = random.nextInt(testWordLimit) + testWordOffset;
            } while (bitSet.get(value));
            mirror[i] = value;
            bitSet.set(value);
        }
    }
}
